package com.learn.im.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.learn.im.domain.Chat;
import com.learn.im.domain.R;
import com.learn.im.servcie.ChatService;
import com.learn.im.utils.AuthUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Emp
 * @version :    1.0
 */
@RestController
@RequestMapping("im/chat")
public class ChatController {
    @Resource
    private ChatService chatService;

    @GetMapping("historyMsg")
    public R historyMsg(HttpServletRequest request){
        String username = AuthUtils.currentUsername(request.getSession());
        List<Chat> history = chatService.list(new LambdaQueryWrapper<Chat>()
                .eq(Chat::getTo, username)
                .eq(Chat::getStatus, false)
        );
        return R.ok(history);
    }
}
